/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.moedik.model;

import com.moedik.classes.Role;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Sammy
 */
public class RoleModel extends Model {
    
    public RoleModel() {
        super();
    }
    
    public ArrayList<Role> getAll() {
        ArrayList<Role> roles = new ArrayList<Role>();
        Statement stmt = null;

        try {
            stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT `roles`.`id` AS `id`, `roles`.`name` AS `name` FROM `roles`");

            while (rs.next()) {
                Role role = new Role(rs.getInt("id"), rs.getString("name"));
                roles.add(role);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }

        return roles;
    }
    
}
